package com.warframe.welcome;

import com.tools.StringContent;
import com.warframe.entity.message.Message;
import com.warframe.message.Executor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class WelCome implements Runnable {
    private Message message;
    private List<String> msg;
    private String defaultGroupCard;

    public WelCome(Message message) {
        this.message = message;
        msg = new ArrayList<>();
    }

    private void getResult() {
        String welcomeStr = StringContent.WELCOME.get(message.getGroupId().toString());
        msg = Arrays.asList(welcomeStr.split("\\|"));
        defaultGroupCard = StringContent.DEFAULTGROUPCARD.get(message.getGroupId().toString());
    }

    @Override
    public void run() {
        Message sendMsg = new Message();
        sendMsg.setGroupId(message.getGroupId());
        sendMsg.setFromQQ(message.getFromQQ());
        getResult();
        for (String eachStr : msg) {
            Message eachMsg = new Message();
            eachMsg.setGroupId(sendMsg.getGroupId());
            eachMsg.setMsg(eachStr);
            eachMsg.setSign(StringContent.SENDGROUP);
            Executor.getInstance().pushMsg(eachMsg);
        }
        if (defaultGroupCard.length() > 0) {
            Executor.getCQ().setGroupCard(sendMsg.getGroupId(), sendMsg.getFromQQ(), defaultGroupCard);
        }
    }
}
